﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.DAL.DocumentCenter;
using Microsoft.SharePoint;
using MS.InformationManagement.Support;

namespace MS.InformationManagement.BLL.SelectfileLibrary
{
    public class SelectFileLibrary
    {

        public IEnumerable<FileEntity> GetFilesCurrentLibrary(int pageIndex, int pageSize, out int totalRecords)
        {
            int startingPosition = pageIndex * pageSize;
            using (var dc = new DCDocumentCenterDataContext(SPContext.Current.Web.Url))
            {
                var files = from file in dc.GetList<Archivo>(SPContext.Current.Web.CurrentUser.LoginName.GetUserWithOutDomain())
                            orderby file.Name ascending
                            select new FileEntity()
                            {
                                CreationDate = file.File.TimeCreated,
                                FileContent = file.File.OpenBinary(),
                                FileName = file.Name,
                                FileSize = (file.File.OpenBinary().Count() / 1024),
                                ItemId = file.Id.Value
                            };

                //string gg = files.Count() + "--";
                totalRecords = files.Count();
                return files.Skip(startingPosition).Take(pageSize);
            }
        }
    }
}
